<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Advanced usage</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GTK+ 2 Reference Manual">
<link rel="up" href="gtk-migrating-GtkRecentChooser.html" title="Migrating from EggRecent to GtkRecentChooser">
<link rel="prev" href="gtkrecent-chooser.html" title="Displaying the Recently Used Documents">
<link rel="next" href="gtk-migrating-GtkLinkButton.html" title="Migrating from GnomeHRef to GtkLinkButton">
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="gtkrecent-chooser.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="gtk-migrating-GtkRecentChooser.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GTK+ 2 Reference Manual</th>
<td><a accesskey="n" href="gtk-migrating-GtkLinkButton.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="gtkrecent-advanced"></a>Advanced usage</h2></div></div></div>
<p>
      The <a class="link" href="GtkRecentChooser.html" title="GtkRecentChooser"><span class="type">GtkRecentChooser</span></a> widgets might display items sorted and filtered,
      either with already supplied or custom sorting and filtering functions.
      The biggest difference from the <span class="structname">EggRecentView</span>
      widgets in EggRecent is that the <a class="link" href="GtkRecentChooser.html" title="GtkRecentChooser"><span class="type">GtkRecentChooser</span></a> widgets will use
      their own copy of the list and will apply the sorting and filtering
      functions only on the copy; this allows the creation of many viewers
      with a single controller, like using many <a class="link" href="GtkTreeView.html" title="GtkTreeView"><span class="type">GtkTreeView</span></a> with a single
      <a class="link" href="GtkTreeModel.html" title="GtkTreeModel"><span class="type">GtkTreeModel</span></a> instance.
    </p>
<p>
      Available sorting methods are:
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="comment">/* no sorting */</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-set-sort-type">gtk_recent_chooser_set_sort_type</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span><span class="normal"> <a href="GtkRecentChooser.html#GTK-RECENT-SORT-NONE:CAPS">GTK_RECENT_SORT_NONE</a></span><span class="symbol">);</span>
<span class="normal">    </span>
<span class="comment">/* most recently used first */</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-set-sort-type">gtk_recent_chooser_set_sort_type</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span><span class="normal"> <a href="GtkRecentChooser.html#GTK-RECENT-SORT-MRU:CAPS">GTK_RECENT_SORT_MRU</a></span><span class="symbol">);</span>
<span class="normal">    </span>
<span class="normal">    </span><span class="comment">/* most recently used last */</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-set-sort-type">gtk_recent_chooser_set_sort_type</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span><span class="normal"> <a href="GtkRecentChooser.html#GTK-RECENT-SORT-LRU:CAPS">GTK_RECENT_SORT_LRU</a></span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      You can create your own sorting function, and the use the
      GTK_RECENT_SORT_CUSTOM method:
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="comment">/* custom sorting function, based on the registration count</span>
<span class="comment"> * (most used first)</span>
<span class="comment"> */</span>
<span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
<span class="function">sort_by_usage_count</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GtkRecentInfo</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">a</span><span class="symbol">,</span>
<span class="normal">                             </span><span class="usertype">GtkRecentInfo</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">b</span><span class="symbol">,</span>
<span class="normal">                             </span><span class="usertype">gpointer</span><span class="normal">       data</span><span class="symbol">)</span>
<span class="normal">        </span><span class="cbracket">{</span>
<span class="normal">  </span><span class="usertype">gint</span><span class="normal"> count_a</span><span class="symbol">,</span><span class="normal"> count_b</span><span class="symbol">;</span>

<span class="normal">  count_a </span><span class="symbol">=</span><span class="normal"> count_b </span><span class="symbol">=</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>

<span class="normal">  </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="GtkRecentManager.html#gtk-recent-info-has-application">gtk_recent_info_has_application</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">a</span><span class="symbol">,</span><span class="normal"> APP_NAME</span><span class="symbol">))</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentManager.html#gtk-recent-info-get-application-info">gtk_recent_info_get_application_info</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">a</span><span class="symbol">,</span><span class="normal"> APP_NAME</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">count_a</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>

<span class="normal">  </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="GtkRecentManager.html#gtk-recent-info-has-application">gtk_recent_info_has_application</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">b</span><span class="symbol">,</span><span class="normal"> APP_NAME</span><span class="symbol">))</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentManager.html#gtk-recent-info-get-application-info">gtk_recent_info_get_application_info</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">b</span><span class="symbol">,</span><span class="normal"> APP_NAME</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&amp;</span><span class="normal">count_b</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>

<span class="normal">  </span><span class="keyword">return</span><span class="normal"> count_a </span><span class="symbol">&lt;</span><span class="normal"> count_b</span><span class="symbol">;</span>
<span class="cbracket">}</span>

<span class="symbol">...</span>

<span class="normal">  </span><span class="comment">/* set custom sorting and set the custom sorting function */</span>
<span class="normal">  </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-set-sort-type">gtk_recent_chooser_set_sort_type</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span>
<span class="normal">                                    <a href="GtkRecentChooser.html#GTK-RECENT-SORT-CUSTOM:CAPS">GTK_RECENT_SORT_CUSTOM</a></span><span class="symbol">);</span>
<span class="normal">  </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-set-sort-func">gtk_recent_chooser_set_sort_func</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">GTK_RECENT_CHOOSER</span><span class="symbol">,</span>
<span class="normal">                                    sort_by_usage_count</span><span class="symbol">,</span>
<span class="normal">                    <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="comment">/* sort function data */</span>
<span class="normal">                    <a href="http://library.gnome.org/devel/glib/unstable/glib-Standard-Macros.html#NULL:CAPS">NULL</a>  </span><span class="comment">/* destroy notify for the data */</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    </p>
<p>
      Filtering is done using the <a class="link" href="GtkRecentFilter.html" title="GtkRecentFilter"><span class="type">GtkRecentFilter</span></a> object, similar to the
      <a class="link" href="gtk-gtkfilefilter.html#GtkFileFilter"><span class="type">GtkFileFilter</span></a> object used by the <a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a> widgets. The
      <a class="link" href="GtkRecentFilter.html" title="GtkRecentFilter"><span class="type">GtkRecentFilter</span></a> object has a set of pre-defined options based on the
      meta-data exposed by the <a class="link" href="GtkRecentManager.html#GtkRecentInfo" title="GtkRecentInfo"><span class="type">GtkRecentInfo</span></a> object. It also allows custom
      filtering function:
      </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="usertype">GtkRecentFilter</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">filter</span><span class="symbol">;</span>

<span class="normal">    filter </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GtkRecentFilter.html#gtk-recent-filter-new">gtk_recent_filter_new</a></span><span class="normal"> </span><span class="symbol">();</span>
<span class="normal">    </span>
<span class="normal">    </span><span class="comment">/* set the user visible name of the filter */</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentFilter.html#gtk-recent-filter-set-name">gtk_recent_filter_set_name</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">filter</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Since Last Month"</span><span class="symbol">);</span>

<span class="normal">    </span><span class="comment">/* set the maximum age of a recently used document */</span>
<span class="normal">    </span><span class="function">gtk_recent_filter_set_age</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">filter</span><span class="symbol">,</span><span class="normal"> </span><span class="number">31</span><span class="symbol">);</span>

<span class="normal">    </span><span class="comment">/* the chooser takes the ownership of the object */</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-add-filter">gtk_recent_chooser_add_filter</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span><span class="normal"> filter</span><span class="symbol">);</span>

<span class="normal">    </span><span class="comment">/* set the currently used filter */</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-set-filter">gtk_recent_chooser_set_filter</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span><span class="normal"> filter</span><span class="symbol">);</span>

<span class="normal">    filter </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GtkRecentFilter.html#gtk-recent-filter-new">gtk_recent_filter_new</a></span><span class="normal"> </span><span class="symbol">();</span>
<span class="normal">    </span><span class="function"><a href="GtkRecentFilter.html#gtk-recent-filter-set-name">gtk_recent_filter_set_name</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">filter</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"Every text file"</span><span class="symbol">);</span>
<span class="normal">    </span><span class="function">gtk_recent_filter_set_mime_type</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">filter</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"text/plain"</span><span class="symbol">);</span>

<span class="normal">    </span><span class="function"><a href="GtkRecentChooser.html#gtk-recent-chooser-add-filter">gtk_recent_chooser_add_filter</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function">GTK_RECENT_CHOOSER</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">chooser</span><span class="symbol">),</span><span class="normal"> filter</span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
      The <a class="link" href="GtkRecentChooserWidget.html" title="GtkRecentChooserWidget"><span class="type">GtkRecentChooserWidget</span></a> and <a class="link" href="GtkRecentChooserDialog.html" title="GtkRecentChooserDialog"><span class="type">GtkRecentChooserDialog</span></a> widgets allow
      multiple filters and the selection of an appropriate one; the
      <a class="link" href="GtkRecentChooserMenu.html" title="GtkRecentChooserMenu"><span class="type">GtkRecentChooserMenu</span></a> widget allows just a single filter object.
    </p>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.18</div>
</body>
</html>